#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define Root 1,1,n
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=3e2+5,M=7e6+5,inf=(1LL<<31)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
string s[N];
int n,m,a[N][N],b[N][N];
int dp0[N];
inline void sol0(){
	int ans=1;
	rep(i,2,m)if(a[1][i]==a[1][i-1])Mul(ans,2);
	cout <<ans<<' ';
}
inline void sub0(){
	repm(i)a[1][i]^=1,sol0(),a[1][i]^=1;
}
int dp[1<<13][2];
inline bool ck(int s,int p){
	return (s>>p)&1;
}
inline int val(int p){
	return 1<<p;
}
inline bool che(int X,int Y){
	return X&&X<=n&&Y&&Y<=m;
}
inline int check(int x,int y,int X,int Y){
	return che(X,Y)&&a[x][y]==a[X][Y];
}
inline void cdp(){
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	bool nw=0;
	int S=(1<<m+1)-1;
	repn(i)repm(j){
		nw^=1;
		rep(s,0,S){
			int w=dp[s][nw^1];dp[s][nw^1]=0;
			if(ck(s,m)&&ck(s,j-1))continue;
			if(ck(s,m)){
				add(dp[s][nw],check(i,j,i,j+1)*w);
				add(dp[s-(s&(1<<m))][nw],w);//不要继续右插头
			}else if(ck(s,j-1)){
				add(dp[s][nw],check(i,j,i+1,j)*w);
				add(dp[s-(s&(1<<j-1))][nw],w);//不要继续上插头
			}else {
				add(dp[s|(1<<m)][nw],check(i,j,i,j+1)*w);
				add(dp[s|(1<<j-1)][nw],check(i,j,i+1,j)*w);
				add(dp[s][nw],w);//啥都不做
			}
		}
	}
	cout<<dp[0][nw]<<' ';
}

inline void sub1(){
	if(m>n){
		repn(i)repm(j)b[j][i]=a[i][j];
		swap(n,m);
		repn(i)repm(j)a[i][j]=b[i][j];
	}
	repn(i){
		repm(j)a[i][j]^=1,cdp(),a[i][j]^=1;	
		cout <<'\n';
	}
}
inline void Main(){
	n=read(),m=read();
	repn(i)cin>>s[i],s[i]='#'+s[i];
	repn(i)repm(j)a[i][j]=s[i][j]-'0';
	if(n==1)return sub0(),void();
	sub1();
}
signed main(){
	freopen("disanti.in","r",stdin);
	freopen("disanti.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}	
